package com.stox.client.ui.javafx.chartingy.model.node;

import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

import com.stox.client.ui.javafx.chartingy.model.axis.DateAxis;
import com.stox.client.ui.javafx.chartingy.model.plot.Data;
import com.stox.shared.model.Bar;
import com.stox.shared.model.Renko;
import com.stox.shared.model.Scrip;

public class RenkoNode extends AbstractPriceNode {

	private final Rectangle rectangle = new Rectangle();

	public RenkoNode(final Data<Scrip, Bar> data) {
		super(data);
		final Renko renko = (Renko) data.getExtraValue();
		rectangle.setFill(renko.isUp() ? Color.GREEN : Color.RED);
		getChildren().add(rectangle);
	}

	@Override
	public void layoutChartChildren() {
		final DateAxis dateAxis = getData().getPlot().primaryChart().getDateAxis();
		final Renko renko = (Renko) getData().getExtraValue();
		final double unitWidth = dateAxis.getUnitWidth();
		final double x = dateAxis.getDisplayPosition(getData().getIndex());
		rectangle.setX(x - (unitWidth / 2));
		rectangle.setY(getDisplayPosition(renko.getHigh()));
		rectangle.setWidth(unitWidth);
		rectangle.setHeight(getDisplayPosition(renko.getLow()) - rectangle.getY());
	}

}
